package cn.fzm.ssm.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Dremeue
 * @create 2019-10-10 23:46
 **/
public class DateUtils {

    /**
     * 日期转换成字符串
     * @return
     */
    public static String dateToString(Date date, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        String format = sdf.format(date);
        return format;
    }

    /**
     * 字符串转换成日期
     * @param time
     * @param pattern
     * @return
     * @throws ParseException
     */
    public static Date stringToDate(String time, String pattern) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        Date date = sdf.parse(time);
        return date;
    }
}
